let util = require('../../../../../common/util/util')

const app = getApp()

let radio = wx.getRecorderManager(); //创建录音

var recordTimeInterval; //录音 时分秒 '00：00'

let innerAudioContext = wx.createInnerAudioContext();

Page({
    data: {
        xDefaultValue: '',
        id: '',
        player: false,
        user: '',
        rept: {},
        recr: {},
        quiz: {},
        value: '',
        xMcShow: false,
        nav: [
            {
                key: 0,
                name: '基本资料',
                mark: false
            },
            // {
            //     key: 1,
            //     name: '提问',
            //     mark: false
            // },
            {
                key: 1,
                name: '练习记录',
                mark: false
            },
            {
                key: 2,
                name: '访谈报告',
                mark: false
            }
        ],
        active: 0,
        record: 0,
        formatedRecordTime: '00:00',
        keep: true,
        recordTime: 0 ,
        act: '',
        ava: '',
        name: '',
        number: '',
        birthday: '',
        gender: '',
        education: '',
        phone: '',
        med: '',
        scrollTop: 0,
        users: [
          { cn: '真实姓名', key: 'real_name', value: '', type: 'text' }, // 真实姓名
          { cn: '出生日期', key: 'birthday', value: '', type: 'text' }, // 出生日期
          { cn: '联系号码', key: 'phone_number', value: '', type: 'text' }, // 联系方式
          { cn: '性别', key: 'sex', value: '', type: 'text', range: ["男", "女"] }, // 性别
          { cn: '工作', key: 'work', value: '', type: 'text', range: ["就业中", "待业中", "失业中", "创业中"], }, // 工作
          { cn: '婚恋状态', key: 'marriage_love_state', value: '', type: 'text', range: ["单身", "已婚", "离婚", "丧偶", "恋爱中"] }, // 婚恋状态
          { cn: '所在地', key: 'city', value: '', type: 'text' }, // 所在地
          { cn: '子女数', key: 'all_child', value: '', type: 'text', range: ["无子女", "1个", "2个", "3个及以上"] }, // 子女数
          { cn: '受教育程度', key: 'education', value: '', type: 'text', range: ["小学", "初中", "高中", "中专", "大专", "本科", "硕士", "博士"] }, // 受教育程度
          // { cn: '紧急联系人姓名', key: 'war_name', value: '', type: 'text' }, // 紧急联系人姓名
          // { cn: '紧急联系人电话', key: 'war_phone', value: '', type: 'number' }, // 紧急联系人电话
          // { cn: '紧急联系人关系', key: 'war_ship', value: '', type: 'text' }, // 与紧急恋人的关系
          // { cn: '电子邮件', key: 'email', value: '', type: 'text' }, // 电子邮件
          { cn: '正在服用的药物', key: 'drugs_being_taken', value: '', type: 'selectcheck'},
          { cn: '存在药物副作用', key: 'drug_side_effects', value: '', type: 'picker3'},
          { cn: '医嘱之外滥用药物', key: 'drug_abuse', value: '', type: 'picker3'},
          { cn: '对自己的状况有很大的困惑', key: 'great_confusion', value: '', type: 'picker3'},
          { cn: '对医疗从业者们失去信心', key: 'lose_confidence', value: '', type: 'picker3'},
          { cn: '不顾一切地想找到治愈方法', key: 'find_cure', value: '', type: 'picker3'},
          { cn: '因为慢性疼痛问题导致收入降低', key: 'lower_income', value: '', type: 'picker3'},
          { cn: '被他人误解为懒散、推卸责任等', key: 'misunderstood_by_others', value: '', type: 'picker3'},
          { cn: '工作、家务等方面表现变差', key: 'poor_performance', value: '', type: 'picker3'},
          { cn: '请假次数明显增加', key: 'leave_increase', value: '', type: 'picker3'},
          { cn: '感到自己职业发展机会有限', key: 'career_development', value: '', type: 'picker3'},
          { cn: '曾被指责编造疼痛事实', key: 'fabricate_painful_facts', value: '', type: 'picker3'},
          { cn: '感到失去别人的尊重（如家人、朋友、同事）', key: 'lose_others_respect', value: '', type: 'picker3'},
          { cn: '感到被他人赋予无法实现的期望', key: 'unrealized_expectations', value: '', type: 'picker3'},



          { cn: '请选择下面的一个数字，以表示过去24小时内您疼痛最剧烈的程度', key: 'most_violent_degree', value: '', type: 'sl' },
          { cn: '请选择下面的一个数字，以表示过去24小时内您疼痛最轻微的程度。', key: 'slightest_degree', value: '', type: 'sl' },  
          { cn: '请选择下面的一个数字，以表示过去24小时内您疼痛的平均程度。', key: 'average_degree_pain', value: '', type: 'sl' },  
          { cn: '请选择下面的一个数字，以表示您目前的疼痛程度。', key: 'current_pain_level', value: '', type: 'sl' },  
          { cn: '在过去的24小时内，由于药物或治疗的作用，您的疼痛缓解了多少？请选择下面的分数，以表示疼痛缓解的程度。', key: 'pain_relief', value: '', type: 'sl' },  
          { cn: '请选择下面的一个数字，以表示过去24小时内疼痛对您日常生活的影响', key: 'Impact_daily_life', value: '', type: 'sl' },  
          { cn: '请选择下面的一个数字，以表示过去24小时内疼痛对您情绪的影响', key: 'Impact_your_mood', value: '', type: 'sl' }, 
          { cn: '请选择下面的一个数字，以表示过去24小时内疼痛对您行走能力的影响', key: 'influence_walking_ability', value: '', type: 'sl' }, 
          { cn: '请选择下面的一个数字，以表示过去24小时内疼痛对您日常工作的影响（包括外出工作和家务劳动）', key: 'impact_daily_work', value: '', type: 'sl' }, 
          { cn: '请选择下面的一个数字，以表示过去24小时内疼痛对您与他人关系的影响', key: 'Influence_relationship', value: '', type: 'sl' }, 
          { cn: '请选择下面的一个数字，以表示过去24小时内疼痛对您睡眠的影响', key: 'effects_sleep', value: '', type: 'sl' }, 
          { cn: '请选择下面的一个数字，以表示过去24小时内疼痛对您生活兴趣的影响', key: 'Influence_life_interest', value: '', type: 'sl' }, 
      
          { cn: '我觉得很难让自己安静下来', key: 'hard_calm_down', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到口干舌燥', key: 'feel_dry', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我好像一点都没有感觉到任何愉快、舒畅', key: 'happy_comfortable', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到呼吸困难(例如：气喘或透不过气来)', key: 'dyspnea', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到很难主动去开始工作', key: 'active_work', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我对事情往往做出过敏反应', key: 'anaphylaxis', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到颤抖（例如，手抖）', key: 'tremble', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我觉得自己消耗了很多精力', key: 'burn_out', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我担心一些可能让自己恐慌或出丑的场合', key: 'panic_occasion', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我觉得自己对不久的将来没有什么可期盼的', key: 'no_expectations', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到忐忑不安', key: 'very_upset', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到很难放松自己', key: 'relax_yourself', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到忧郁沮丧', key: 'melancholy_depression', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我无法容忍任何阻碍我继续工作的事情', key: 'melancholy_depression', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到快要崩溃了', key: 'collapse', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我对任何事情都不能产生热情', key: 'generate_enthusiasm', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我觉得自己不怎么配做人', key: 'unworthy_being_man', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我发觉自己很容易被触怒', key: 'offended', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '即使在没有明显的体力活动时,我也感到心律不正常', key: 'physical_activity', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我无缘无故地感到害怕', key: 'feel_afraid', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
          { cn: '我感到生命毫无意义', key: 'meaning_life', value: '', type: 'picker2', range: ["不符合", "有时符合", "常常符合", "总是符合"], },
        
          { cn: '尽管痛苦，我也可以享受事物', key: 'enjoy_things', value: '', type: 'sll' },
          { cn: '尽管痛苦，我可以做大部分的家务（例如整理，洗碗等）', key: 'housework', value: '', type: 'sll' },
          { cn: '尽管痛苦，我可以像往常一样，和朋友或家人进行交往', key: 'normal_communication', value: '', type: 'sll' },
          { cn: '在大多数情况下，我可以应付我的痛苦', key: 'dealing_pain', value: '', type: 'sll' },
          { cn: '尽管痛苦（“工作”包括家务，付费和无酬工作），我可以做某种形式的工作', key: 'formal_work', value: '', type: 'sll' },
          { cn: '我仍然可以做许多我喜欢做的事情，如兴趣爱好或休闲活动', key: 'like_things', value: '', type: 'sll' },
          { cn: '尽管痛苦，我可以无需额外的治疗即可应付我的疼痛', key: 'dealing_my_pain', value: '', type: 'sll' },
          { cn: '尽管痛苦，我仍然可以在生活中完成我的大部分目标', key: 'most_goals', value: '', type: 'sll' },
          { cn: '尽管痛苦，我也能过正常的生活方式', key: 'normal_lifestyle', value: '', type: 'sll' },
          { cn: '尽管痛苦，我也可以逐渐变得更加活跃', key: 'more_active', value: '', type: 'sll' },
        ],
        check1:false,
        check2:false,
        check3:false,
        check4:false,
        ids:'',
        xLi:''
    },

    onLoad: function (opt) {
        let that = this
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.on('xToDetail', function (data) {
            console.log(data)
            that.setData({
                act: data.act,
                ids: data.id,
                ava: data.ava,
                name: data.name,
                // number: data.number,
                // birthday: data.birthday,
                // gender: data.gender,
                // education: data.education,
                // phone: data.phone,
                // med: data.other_drugs
            })
            that.xGetUser(data.id)
        })

    },
    onShow:function(){
      
    },
    xInit: async function (id, act) {
        let that = this
        await wx.cloud.callFunction({
            name: 'digital_therapy',
            data: {
                action: "get_treatment_stage_by_userid",
                user_openid: id
            }
        }).then(res => {
            let data = res.result
            if(data.stage.length > 0){
                data.stage[0].begin_time = util.formatDate_chinese(new Date(data.stage[0].begin_time))
            }
            for(var i in data.job_record){
                   data.job_record[i].create_time = util.formatTime_chinese(new Date(data.job_record[i].create_time))
              
            }
            for(var i in data.pain_diary){
              data.pain_diary[i].create_time = util.formatTime_chinese(new Date(data.pain_diary[i].create_time))
            }
            for(var i in data.practice_feeling){
              data.practice_feeling[i].create_time = util.formatTime_chinese(new Date(data.practice_feeling[i].create_time))
            }
            // for(var i in data.retroaction){
            //   data.retroaction[i].create_time = util.formatTime_chinese(new Date(data.retroaction[i].create_time))
            // }
            data.stage.begin_time = util.formatTime_chinese(new Date(data.stage.begin_time))
            that.setData({
                user: data
            })
            if(data.stage.week>0){
              act = 1
            }
            if (act != '' || act != undefined) {
                that.setData({
                    active: act
                })
                let edet = {
                    currentTarget : {
                        dataset : {
                            key : act
                        }
                    }
                }
                this.xTab(edet)
            }
            
        })


        wx.cloud.callFunction({
          name: "user",
          data: {
            action: "get_user_info",
            _openid: id //当前患者的openid
          },
          success: function (res) {
              that.setData({
                xLi:res.result.calculated_value
              })
          }
        })
     
    },

    xTab: function (e) {
        let that = this
        let key = 0
        key = e.currentTarget.dataset.key
        that.setData({
            active: key
        })
        switch (key) {
            case 1:
              that.xRept()
                // that.xQuiz()
                break;
            case 2:
              that.xRecr()
                // that.xRept()
                break;
            case 3:
                // that.xRecr()
                break;
            default:
                console.log('none')
        }
    },
    // 联系用户
    xToMessage:function(){
        let that =this;
        wx.navigateTo({
          url: '/subdter/pages/mine/xtask/chat/index?id='+that.data.id+'&name='+that.data.name+'&ava='+that.data.ava
        })
    },
    xQuiz: function () {
        let that = this
        let id = that.data.id
        console.log(id)
        let _dataObj = {
            object_openid: id
        }
        wx.cloud.callFunction({
            name: 'consulting_message',
            data: {
                action: "get_oneOnone_messages",
                dataObj: _dataObj
            }
        }).then(res => {
            let data = res.result
            for (var i in data) {
                data[i].quote_info[0].create_time = util.formatDate_chinese(new Date(data[i].quote_info[0].create_time))
                // if(data[i].quote_info[0].content.content.audio.duration){
                //     let time = data[i].quote_info[0].content.content.audio.duration/10
                //     let nTime = util.formatvoiceTime(time)
                //     data[i].quote_info[0].content.content.audio.duration = nTime
                // }
            }
            if(data[data.length-1].quote_info[0].business_type === 4){
              data[data.length-1].show=true
            }
            that.setData({
                quiz: data
            })

            that.xScrollBottom()
        })
    },

    xRept: function () {
        let that = this
        let id = that.data.id
        let _dataObj = {
          week: that.data.user.stage.week, //用户当前阶段
          user_openid:that.data.id//患者的openid
        }
        wx.cloud.callFunction({
          name: 'consultant_workbench',
          data: {
            action: "get_exercise_content",
            dataObj: _dataObj
          }
        }).then(res => {
            console.log("返回数据:", res.result)
            let data = res.result
            for(let index in data){
              for(let i in data[index].data){
                 for(let ii in data[index].data[i].diary_practice){
                  data[index].data[i].diary_practice[ii].create_time=util.formatTime_emotion(new Date(data[index].data[i].diary_practice[ii].create_time))
                 }
                 for(let ii in data[index].data[i].practice_feeling){
                  data[index].data[i].practice_feeling[ii].create_time=util.formatTime_emotion(new Date(data[index].data[i].practice_feeling[ii].create_time))
                 }
                 for(let ii in data[index].data[i].pain_diary_completed){
                  data[index].data[i].pain_diary_completed[ii].create_time=util.formatTime_emotion(new Date(data[index].data[i].pain_diary_completed[ii].create_time))
                 }
              }
            }
            that.setData({
                rept: data
            })

            // that.xScrollBottom()
        })
    },

    xRecr: function () {
        let that = this
        let id = that.data.id
        // let id = 'ofd3X5Y7pYaUMHEzBZ1t38AvZzU4'
        wx.cloud.callFunction({
            name: 'digital_therapy',
            data: {
                action: "get_interview_list_by_user",
                user_openid: id
            }
        }).then(res => {
            console.log("咨询访谈:", res)
            let data = res.result
            for (var i in data) {
                data[i].begin_time = util.formatDate_chinese(new Date(data[i].begin_time))
            }
            that.setData({
                recr: data
            })
            that.xScrollBottom()
        })
    },

    xToWrite: function (e) {
        let that = this
        let id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: '/subdter/pages/mine/rec/detail/index?id=' + id,
        })
    },
    // 日记详情
    xTodayremb:function(e){
      // let d = e.currentTarget.dataset.datas
      // let type = e.currentTarget.dataset.type
      // let name =e.currentTarget.dataset.name
      // var datas={}
      // console.log(d)
      // if(type==1){
      //   for(let index in d.writing_practice_return.json_content){
      //     d.writing_practice_return.json_content[index].content =String(d.writing_practice_return.json_content[index].content )
      //     delete d.writing_practice_return.json_content[index].display_type
      //   }
      //   datas ={
      //     json_content: d.writing_practice_return.json_content,
      //     writing_class_number:name,
      //     create_time:d.create_time
      //   }
      //   console.log(datas)
      // }else if(type==2){
      //   datas = d
      // }else if(type==3){
      //   datas = {
      //     create_time:d.create_time,
      //     practice_feeling:d.practice_feeling,
      //   } 
      // }
      // wx.navigateTo({
      //   url: '/subuser/pages/mine/detail/index?datas='+JSON.stringify(datas)+'&type='+type,
      // })
      
    },
    xToseetype:function(e){
        let that =this;
        let d =e.currentTarget.dataset.d
        let sub_classification_number=''
        let name = d.name
        if(d.num==2){
          sub_classification_number=d.writing_task[0].writing_class_number
        }
        wx.navigateTo({
           url: '/subuser/pages/mine/detail/index?id='+that.data.ids+'&sub_classification_number='+sub_classification_number+'&num='+d.num+'&name='+name
        })
    },
    input: function (e) {
        let that = this
        let value = e.detail.value
        that.setData({
            value: value
        })
    },

    sub: function () {
        let that = this
        let value = that.data.value
        let id = that.data.id
        if (value === '') {
            wx.showToast({
                title: '请输入内容',
                icon: 'none'
            })
        } else {
            let _dataObj = {
                to_openid: id,
                message_type: 1,
                business_type: 6,
                content: {
                    title: value,
                    content: {
                        pic: "",
                        text: value,
                        audio: "",
                        parameter: ""
                    }
                }
            }
            wx.cloud.callFunction({
                name: 'consulting_message',
                data: {
                    action: "send_message",
                    dataObj: _dataObj
                }
            }).then(res => {
                wx.showToast({
                    title: '发送成功',
                    icon: 'none'
                })
                that.setData({
                    xDefaultValue: ''
                })
                that.xQuiz()
            })
        }
    },

    voice: function (e) {
        var that = this
        let id = ''
        if (e.currentTarget.dataset.id != undefined || e.currentTarget.dataset.id != '') {
            id = e.currentTarget.dataset.id
        } else {
            id = that.data.id
        }
        that.setData({
            record: 1,
            xMcShow: true
        })
        recordTimeInterval = setInterval(function () { //计算时分秒
            var recordTime = that.data.recordTime += 1
            that.setData({
                formatedRecordTime: util.formatvoiceTime(that.data.recordTime),
                recordTime: recordTime
            })
        }, 1000)
        const options = {
            duration: 30000,
            sampleRate: 44100,
            numberOfChannels: 1,
            encodeBitRate: 192000,
            format: 'mp3'
        }
        radio.start(options);
        radio.onStart(res => {
            console.log('监听录音', res)
        });
    },

    voiced: function () {
        console.log('录音结束了')
        let that = this;
        let id = that.data.id
        clearInterval(recordTimeInterval);
        that.setData({
            xMcShow: false
        })
        radio.stop(); //录音结束
        radio.onStop((res) => { //录音结束
            // that.stopRecord
            console.log('录音结束', res);
            this.setData({
                record: res.tempFilePath,
                musicUrl: res.tempFilePath, //录音音频
                duration: res.duration, //音频时长时间戳
                record: true,
            })
            if (res.duration < 1000) {
                wx.showToast({
                    title: '说的太快了',
                    icon: 'none'
                })
            } else {
                let url = ''
                wx.cloud.uploadFile({
                    cloudPath: 'profile/' + id + "/" + new Date().getTime() + '.mp3',
                    filePath: res.tempFilePath
                }).then(xRes => {
                    wx.cloud.getTempFileURL({
                        fileList: [xRes.fileID],
                        success: xDoRes => {
                            console.log(xDoRes)
                            let url = xDoRes.fileList[0].tempFileURL
                            let _dataObj = {
                                to_openid: id,
                                message_type: 3,
                                business_type: 6,
                                content: {
                                    title: 'voice',
                                    content: {
                                        pic: "",
                                        text: "",
                                        audio: {
                                            record: res.tempFilePath,
                                            musicUrl: url, //录音音频
                                            duration: res.duration, //音频时长时间戳
                                            record: true,
                                        },
                                        parameter: ""
                                    }
                                }
                            }
                            wx.cloud.callFunction({
                                name: 'consulting_message',
                                data: {
                                    action: "send_message",
                                    dataObj: _dataObj
                                }
                            }).then(res => {
                                wx.showToast({
                                    title: '发送成功',
                                    icon: 'none'
                                })
                                that.setData({
                                    xDefaultValue: ''
                                })
                                let edet = {
                                    currentTarget : {
                                        dataset : {
                                            key : that.data.active
                                        }
                                    }
                                }
                                // let key = that.data.active + 1
                                that.xTab(edet)
                            })
                        }
                    })
                })
            }
        })
    },

    player: function (e) {
        let that = this
        let params = e.currentTarget.dataset
        console.log(that.data.player)
        that.setData({
            playStatus: false
        })
        var musicUrl = params.vocd
        console.log(params)
        console.log('musicUrl', musicUrl)
        innerAudioContext.src = musicUrl;
        innerAudioContext.autoplay = true
        innerAudioContext.play();
        console.log(that.data.player)
        innerAudioContext.onTimeUpdate((res) => {
            console.log('onTimeUpdate', res)
            console.log("duratio的值：", innerAudioContext.duration)
            that.setData({
                duration: innerAudioContext.duration.toFixed(2) * 100,
                curTimeVal: innerAudioContext.currentTime.toFixed(2) * 100,
                formatedPlayTime: this.formatvoiceTime(innerAudioContext.currentTime)
            })
            if (innerAudioContext.duration.toFixed(2) - innerAudioContext.currentTime.toFixed(2) <= 0) {
                that.setStopState(that)
                console.log(1)
            }
            innerAudioContext.onEnded(() => {
                console.log(1)
                that.setStopState(that)
            })
        })
    },

    oSub: function (e) {
        wx.showLoading({
            title: '发送中',
        })
        let that = this
        let params = e.currentTarget.dataset
        let value = that.data.value
        let _objData = {
            _id: params.id,
            summary: [
                {
                    type: 1,
                    content: value
                }
            ]
        }
        wx.cloud.callFunction({
            name: 'digital_therapy',
            data: {
                action: "add_interview_summary",
                objData: _objData
            }
        }).then(res => {
            that.setData({
                xDefaultValue : ''
            })
            wx.showToast({
                title: '发送成功',
                icon: 'none'
            })
            that.xRept()
        })
    },

    xvoice: function (e) {
        var that = this
        let id = ''
        if (e.currentTarget.dataset.id != undefined || e.currentTarget.dataset.id != '') {
            id = e.currentTarget.dataset.id
        } else {
            id = that.data.id
        }
        that.setData({
            record: 1,
            xMcShow: true
        })
        recordTimeInterval = setInterval(function () { //计算时分秒
            var recordTime = that.data.recordTime += 1
            that.setData({
                formatedRecordTime: util.formatvoiceTime(that.data.recordTime),
                recordTime: recordTime
            })
        }, 1000)
        const options = {
            duration: 30000,
            sampleRate: 44100,
            numberOfChannels: 1,
            encodeBitRate: 192000,
            format: 'mp3'
        }
        radio.start(options);
        radio.onStart(res => {
            console.log('监听录音', res)
        });
    },

    xvoiced: function (e) {
        console.log('录音结束了')
        let that = this;
        let id = e.currentTarget.dataset.id
        clearInterval(recordTimeInterval);
        that.setData({
            xMcShow: false
        })
        radio.stop(); //录音结束
        radio.onStop((res) => { //录音结束
            // that.stopRecord
            console.log('录音结束', res);
            this.setData({
                record: res.tempFilePath,
                musicUrl: res.tempFilePath, //录音音频
                duration: res.duration, //音频时长时间戳
                record: true,
            })
            if (res.duration < 1000) {
                wx.showToast({
                    title: '说的太快了',
                    icon: 'none'
                })
            } else {
                let url = ''
                wx.cloud.uploadFile({
                    cloudPath: 'profile/' + id + "/" + new Date().getTime() + '.mp3',
                    filePath: res.tempFilePath
                }).then(xRes => {
                    wx.cloud.getTempFileURL({
                        fileList: [xRes.fileID],
                        success: xDoRes => {
                            console.log(xDoRes)
                            let url = xDoRes.fileList[0].tempFileURL
                            let _objData = {
                                _id: id ,
                                summary: [
                                    {
                                        type : 3 ,
                                        content : {
                                            record: res.tempFilePath,
                                            musicUrl: url,
                                            duration: res.duration,
                                            record: true,
                                        }
                                    }
                                ]
                            }
                            wx.cloud.callFunction({
                                name: 'digital_therapy',
                                data: {
                                    action: "add_interview_summary",
                                    objData: _objData
                                }
                            }).then(res => {
                                wx.showToast({
                                    title: '发送成功',
                                    icon: 'none'
                                })
                                that.setData({
                                    xDefaultValue: ''
                                })
                                that.xRept()
                            })
                        }
                    })
                })
            }
        })
    },

    xplayer: function (e) {
        let that = this
        let params = e.currentTarget.dataset
        console.log(that.data.player)
        that.setData({
            playStatus: false
        })
        var musicUrl = params.vocd
        console.log(params)
        console.log('musicUrl', musicUrl)
        innerAudioContext.src = musicUrl;
        innerAudioContext.autoplay = true
        innerAudioContext.play();
        console.log(that.data.player)
        innerAudioContext.onTimeUpdate((res) => {
            console.log('onTimeUpdate', res)
            console.log("duratio的值：", innerAudioContext.duration)
            that.setData({
                duration: innerAudioContext.duration.toFixed(2) * 100,
                curTimeVal: innerAudioContext.currentTime.toFixed(2) * 100,
                formatedPlayTime: this.formatvoiceTime(innerAudioContext.currentTime)
            })
            if (innerAudioContext.duration.toFixed(2) - innerAudioContext.currentTime.toFixed(2) <= 0) {
                that.setStopState(that)
                console.log(1)
            }
            innerAudioContext.onEnded(() => {
                console.log(1)
                that.setStopState(that)
            })
        })
    },


    xGetUser : function (id) {
        let that = this
        let act = that.data.act
        wx.cloud.callFunction({
            name: 'user',
            data: {
                action: "get_user_info",
                _openid: id
            }
        }).then( async res => {
            let data = res.result
            that.setData({
                id: data.user_id,
                ava: data.avatarUrl,
                name: data.real_name,
                birthday: data.birthday,
                gender: data.gender,
                education: data.education,
                phone: data.phone_number,
                med: data.other_drugs,
                war_name: data.war_name,
                war_phone: data.war_phone,
                war_ship: data.war_ship,
                all_child: data.all_child,
                work: data.work,
                user_number: data.user_number,
                user_number_prefix : data.user_number_prefix
            })
            let user = that.data.users
            for(var i in data){
                for(var j in user){
                    if(user[j].key === i){
                        // console.log(user[j].key)
                        user[j].value = data[i]
                    }
                }
            }
            that.setData({
              users : user
            })
            that.xInit(data.user_id , act)
        })
    },

    xScrollBottom: function () {
        let that = this
        wx.createSelectorQuery().select('#ownContainer').boundingClientRect(function (rect) {
            wx.pageScrollTo({
                scrollTop: rect.bottom,
                duration: 100
            })
            that.setData({
                scrollTop: rect.height - that.data.scrollTop
            });
        }).exec();
    }
})